#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QWidget>
#include <QScreen>
#include <QDateTime>
#include <QTimeZone>
#include <QDebug>
#include <QRegExp>
#include <QRandomGenerator>
#include <QMessageBox>
#include <QImage>
#include <QPixmap>
#include <QFileDialog>
#include <QFile>
#include <QDesktopServices>
#include <QUrl>
#include <QPainter>
#include <QMovie>

QMessageBox * msgBox;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("百宝工具箱V1.00");
    QScreen *screen = QGuiApplication::primaryScreen();
    QRect screenGeometry = screen->availableGeometry();
    // 计算新窗口大小为屏幕大小的倍数
    int newWidth = screenGeometry.width() * 0.6;
    int newHeight = screenGeometry.height() * 0.7;
    resize(newWidth, newHeight);
    ui->statusbar->showMessage("开发者:YQiang");

    camera = new QCamera(this);
    imageCapture = new QCameraImageCapture(camera);
    capturetimer = new QTimer;
    // 获取应用程序所在的目录
    QString appDir = QCoreApplication::applicationDirPath();
    // 设置定时器以定期捕获图像
    connect(capturetimer, &QTimer::timeout, this, [=]() {imageCapture->capture(appDir + "/buff.jpg");});
    // 连接图像捕获信号到槽函数
    connect(imageCapture, &QCameraImageCapture::imageCaptured, this, &MainWindow::processFrame);
    camera->stop();
    capturetimer->stop();
    UISetInit();
}

MainWindow::~MainWindow()
{
    camera->stop();
    capturetimer->stop();
    delete ui;
}

void MainWindow::UISetInit()
{
    ui->tabWidget->setTabText(0,"工具箱1");
    ui->tabWidget->setTabText(1,"工具箱2");
    ui->lineEdit_rand->setReadOnly(true);
    ui->lineEdit_output->setReadOnly(true);
    ui->lineEdit_virtualage->setReadOnly(true);
    ui->lineEdit_trueage->setReadOnly(true);
    ui->lineEdit_animal->setReadOnly(true);
    ui->lineEdit_star->setReadOnly(true);
    ui->lineEdit_lifedays->setReadOnly(true);
    ui->lineEdit_lifehour->setReadOnly(true);
    ui->lineEdit_path->setReadOnly(true);
    // 创建一个 QMovie 对象并加载 GIF 文件
    movie = new QMovie(":/img/2.gif");
    // 检查 GIF 是否加载成功
    if (!movie->isValid()) {
        qDebug() << "Failed to load the GIF file.";
    }
    // 将 QMovie 设置到 QLabel 上
    ui->label_16->setMovie(movie);
    ui->label_16->setScaledContents(true);
    // 开始播放动画
    movie->start();
    // 创建一个 QMovie 对象并加载 GIF 文件
    movie = new QMovie(":/img/410.gif");
    // 检查 GIF 是否加载成功
    if (!movie->isValid()) {
        qDebug() << "Failed to load the GIF file.";
    }
    // 将 QMovie 设置到 QLabel 上
    ui->label_17->setMovie(movie);
    ui->label_17->setScaledContents(true);
    // 开始播放动画
    movie->start();
}

/************************************************************************
 *北京时间戳转换器
************************************************************************/
void MainWindow::on_pushButton_clear_clicked()
{
    ui->lineEdit_year->clear();
    ui->lineEdit_month->clear();
    ui->lineEdit_day->clear();
    ui->lineEdit_hour->clear();
    ui->lineEdit_min->clear();
    ui->lineEdit_sec->clear();
    ui->lineEdit_timestamp->clear();
}

void MainWindow::on_pushButton_timestamp_clicked()
{
    QString input_time = ui->lineEdit_year->text()+"-"+ui->lineEdit_month->text()+"-"+ui->lineEdit_day->text()+" "+\
                    ui->lineEdit_hour->text()+":"+ui->lineEdit_min->text()+":"+ui->lineEdit_sec->text();
    QDateTime dateTime = QDateTime::fromString(input_time, "yyyy-MM-dd HH:mm:ss");
    if (!dateTime.isValid())
    {
        ui->lineEdit_timestamp->setText("无效的日期时间格式");
        return;
    }
    // 设置时区为北京时间 (UTC+8)
    QTimeZone timeZone("Asia/Shanghai");
    dateTime.setTimeZone(timeZone);
    // 转换为 UTC 时间
    QDateTime utcDateTime = dateTime.toUTC();
    // 获取 Unix 时间戳
    qint64 timestamp = utcDateTime.toSecsSinceEpoch();
    ui->lineEdit_timestamp->setText(QString::number(timestamp));
}


void MainWindow::on_pushButton_time_clicked()
{
    QString text = ui->lineEdit_timestamp->text();
    // 判断时间戳是否有效
    QRegExp re("\\d+");
    if (!re.exactMatch(text))
    {
        return;
    }
    // 获取时间戳
   qint64 currentTimestamp = ui->lineEdit_timestamp->text().toULong();
   // 将时间戳转换为 QDateTime 对象
   QDateTime dateTime = QDateTime::fromSecsSinceEpoch(currentTimestamp);
   // 设置时区为北京时间 (UTC+8)
   QTimeZone timeZone("Asia/Shanghai");
   dateTime.setTimeZone(timeZone);
   // 格式化日期时间字符串
   QString formattedDateTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");
   QStringList dateTimeParts = formattedDateTime.split(" ");
   if (dateTimeParts.size() != 2) return; // 检查格式是否正确
   QStringList dateParts = dateTimeParts[0].split("-");
   QStringList timeParts = dateTimeParts[1].split(":");
   if (dateParts.size() == 3 && timeParts.size() == 3)
   {
       ui->lineEdit_year->setText(dateParts[0]);
       ui->lineEdit_month->setText(dateParts[1]);
       ui->lineEdit_day->setText(dateParts[2]);
       ui->lineEdit_hour->setText(timeParts[0]);
       ui->lineEdit_min->setText(timeParts[1]);
       ui->lineEdit_sec->setText(timeParts[2]);
   }
}

void MainWindow::on_pushButton_curtimestamp_clicked()
{
    // 获取当前时间戳
    qint64 currentTimestamp = QDateTime::currentSecsSinceEpoch();
    // 将时间戳转换为 QDateTime 对象
    QDateTime dateTime = QDateTime::fromSecsSinceEpoch(currentTimestamp);
    // 设置时区为北京时间 (UTC+8)
    QTimeZone timeZone("Asia/Shanghai");
    dateTime.setTimeZone(timeZone);
    // 格式化日期时间字符串
    QString formattedDateTime = dateTime.toString("yyyy-MM-dd HH:mm:ss");
    QStringList dateTimeParts = formattedDateTime.split(" ");
    if (dateTimeParts.size() != 2) return; // 检查格式是否正确
    QStringList dateParts = dateTimeParts[0].split("-");
    QStringList timeParts = dateTimeParts[1].split(":");
    if (dateParts.size() == 3 && timeParts.size() == 3)
    {
        ui->lineEdit_year->setText(dateParts[0]);
        ui->lineEdit_month->setText(dateParts[1]);
        ui->lineEdit_day->setText(dateParts[2]);
        ui->lineEdit_hour->setText(timeParts[0]);
        ui->lineEdit_min->setText(timeParts[1]);
        ui->lineEdit_sec->setText(timeParts[2]);
    }
    ui->lineEdit_timestamp->setText(QString::number(currentTimestamp));
}

/************************************************************************
 *随机数生成器
************************************************************************/
void MainWindow::on_pushButton_make_clicked()
{
    // 获取当前时间戳
    qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
    // 使用时间戳初始化随机数生成器
    QRandomGenerator randomGenerator(currentTimestamp);
    // 设定范围
    int min = ui->lineEdit_min_2->text().toInt();
    int max = ui->lineEdit_max->text().toInt();
    // 生成随机数
    int randomValue = randomGenerator.bounded(min, max + 1); // bounded函数的上限是开区间，所以需要+1
    ui->lineEdit_rand->setText(QString::number(randomValue));
}

/************************************************************************
 *CRC校验计算器
************************************************************************/
// 计算Modbus CRC16的函数
uint16_t calculateCRC16(const uint16_t *data,uint16_t data_len)
{
    uint16_t crc = 0xFFFF; // 初始值
    if(data_len == 0)
    {
        return 0;
    }
    for (int pos = 0; pos < data_len; ++pos) {
        crc ^= static_cast<quint8>(data[pos]); // XOR byte into least sig. byte of crc
        for (int i = 8; i != 0; --i) { // Loop over each bit
            if ((crc & 0x0001) != 0) { // If the LSB is set
                crc >>= 1; // Shift right and XOR 0xA001
                crc ^= 0xA001;
            } else { // Else LSB is not set
                crc >>= 1; // Just shift right
            }
        }
    }
    return crc;
}
uint16_t stringTohex(QString text, uint16_t *outdata)
{
    uint16_t len = 0;
    // 使用split方法将字符串按空格分割成QStringList
    QStringList strList = text.split(' ', QString::SkipEmptyParts);
    // 遍历QStringList并将每个元素转换为uint
    for (const QString &s : strList)
    {
        bool ok;
        int value = s.toUInt(&ok,16);
        if (ok)
        {
            *outdata = value;
            outdata++;
            len++;
        } else
        {
            qDebug() << "Conversion failed" ;
            QMessageBox * msgBox = new QMessageBox(QMessageBox::Warning, "提示", "请输入正确的16进制格式");
            msgBox->show();
            return 0;
        }
    }
    return len;
}

enum{
    CRC16,
    CRC32
};
void MainWindow::on_pushButton_make_2_clicked()
{
    uint16_t data[100];//最大支持输入一百个字节的数据
    uint16_t data_len = 0;
    uint16_t crc = 0;
    QString text = ui->lineEdit_input->text();
    data_len = stringTohex(text,data);
    qDebug() << "data_len"<<data_len ;
    switch (ui->comboBox_crctype->currentIndex())
    {
    case CRC16:
        crc = calculateCRC16(data,data_len);
        if(crc != 0)
        {
            ui->lineEdit_output->setText("MSB-"+QString::number(crc>>8,16).toUpper()+\
                                     "   LSB-"+QString::number(crc&0xff,16).toUpper());
        }
        break;
    case CRC32:
        break;
    default:
        break;
    }
}

/************************************************************************
 *活了多久计算器
************************************************************************/
// 计算周岁年龄的函数
int calculateAge(int birthYear, int birthMonth, int birthDay)
{
    // 获取当前时间
    time_t t = time(NULL);
    struct tm currentTime = *localtime(&t);
    int currentYear = currentTime.tm_year + 1900; // tm_year是从1900年开始的
    int currentMonth = currentTime.tm_mon + 1;    // tm_mon是从0开始的
    int currentDay = currentTime.tm_mday;
    // 计算年龄
    int age = currentYear - birthYear;
    // 如果当前日期还没有到出生日期，则年龄减一
    if (currentMonth < birthMonth || (currentMonth == birthMonth && currentDay < birthDay)) {
        age--;
    }
    return age;
}

// 计算出生属相
const char* getZodiacSign_animal(int year)
{
    const char* zodiacs[] = {
        "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"
    };
    return zodiacs[year % 12];
}

// 计算出生星座
const char* getZodiacSign_star(int month, int day)
{
    const char* zodiacs[] = {
        "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"
    };
    int days[] = {19, 18, 20, 20, 20, 21, 22, 22, 22, 22, 21, 21 };
    if(month != 12)
    {
        int index = (month) % 12;
        if (day <= days[index - 1]) {
            return zodiacs[index - 1];
        } else {
            return zodiacs[index];
        }
    }else
    {
        if (day <= days[11]) {
            return zodiacs[11];
        } else {
            return zodiacs[12];
        }
    }
}

void MainWindow::on_pushButton_make_3_clicked()
{
    QDate date = ui->calendarWidget->selectedDate();
    int birth_year = date.year();qDebug() << "birth_year"<<birth_year ;
    int birth_month = date.month();qDebug() << "birth_month"<<birth_month ;
    int birth_day = date.day();qDebug() << "birth_day"<<birth_day ;
    // 获取当前日期
    QDate currentDate = QDate::currentDate();
    // 提取年、月、日
    int cur_year = currentDate.year();qDebug() << "cur_year"<<cur_year ;
    int cur_month = currentDate.month();qDebug() << "cur_month"<<cur_month ;
    int cur_day = currentDate.day();qDebug() << "cur_day"<<cur_day ;
    ui->lineEdit_virtualage->setText(QString::number(cur_year - birth_year + 1));
    int trueage = calculateAge(birth_year,birth_month,birth_day);
    ui->lineEdit_trueage->setText(QString::number(trueage));
    const char* zodiacSign_animal = getZodiacSign_animal(birth_year);
    ui->lineEdit_animal->setText(QString("%1").arg(zodiacSign_animal));
    const char* zodiacSign_star = getZodiacSign_star(birth_month,birth_day);
    ui->lineEdit_star->setText(QString("%1").arg(zodiacSign_star));
    // 计算两个日期之间的天数
    int daysLived = date.daysTo(currentDate);
    ui->lineEdit_lifedays->setText("你在地球一共生活了"+QString::number(daysLived)+"天了");
    ui->lineEdit_lifehour->setText("你在地球一共生活了"+QString::number(daysLived * 24)+"小时了");
}

/************************************************************************
 *图片格式转换
************************************************************************/
QString gfilePath;
void MainWindow::on_pushButton_addpicture_clicked()
{
    // 打开文件对话框选择PNG和JPG图片
    QStringList filters;
    filters << "Image files (*.png *.jpg)";
    QString filePath = QFileDialog::getOpenFileName(nullptr, "选择图片", "", filters.join(";;"));
    if (!filePath.isEmpty())
    {
        gfilePath = filePath;
        ui->lineEdit_path->setText(gfilePath);
    }else
    {
        qWarning() << "No image selected!";
        gfilePath.clear();
        ui->lineEdit_path->setText(gfilePath);
        return;
    }
}

enum{
    PNGtoICO,
    JPGtoICO,
    PNGtoJPG,
    JPGtoPNG
};
void MainWindow::on_pushButton_change_clicked()
{
    if(gfilePath.isEmpty())
    {
        QMessageBox * msgBox = new QMessageBox(QMessageBox::Warning, "提示", "请先添加图片");
        msgBox->show();
        return;
    }
    // 使用 QFileInfo 提取文件夹路径
    QFileInfo fileInfo(gfilePath);
    // 加载输入图片
    QImage image(gfilePath);
    if (image.isNull()) {
       qWarning() << "Failed to load image:" << gfilePath;
       return;
    }
    QMessageBox * msgBox;
    int sizes[6] = {16, 32, 48, 64, 128, 256}; // 常见的ICO尺寸
    QString outPath;
    QIcon icon;
    switch(ui->comboBox_picturetype->currentIndex())
    {
    case PNGtoICO:
    case JPGtoICO:
        // 创建图标并添加图像        
        icon.addPixmap(QPixmap::fromImage(image));
        //将QIcon对象保存为ICO文件
        for (int size = 0; size < 6; size++)
        {
            outPath = fileInfo.absolutePath() + "/" + fileInfo.baseName() + QString::number(sizes[size])+".ico";
            if (!icon.pixmap(sizes[size], sizes[size]).save(outPath, "ICO"))
            {
                msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换失败，请检查图片是否正常");
                msgBox->show();
                return;
            }
        }
        msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换成功，已保存到原目录下");
        msgBox->show();
        break;
    case PNGtoJPG:
        // 保存为JPG格式
        outPath = fileInfo.absolutePath() + "/" + fileInfo.baseName() +".jpg";
        if (!image.save(outPath, "JPG")) {
            msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换失败，请检查图片是否正常");
            msgBox->show();
            return;
        }
        msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换成功，已保存到原目录下");
        msgBox->show();
        break;
    case JPGtoPNG:
        // 保存为PNG格式
        outPath = fileInfo.absolutePath() + "/" + fileInfo.baseName() +".png";
        if (!image.save(outPath, "PNG")) {
            msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换失败，请检查图片是否正常");
            msgBox->show();
            return;
        }
        msgBox = new QMessageBox(QMessageBox::Information, "提示", "转换成功，已保存到原目录下");
        msgBox->show();
        break;
    default:
        break;
    }
}

void MainWindow::on_pushButton_openfile_clicked()
{
    // 打开文件资源管理器并显示所选文件夹
    if(gfilePath.isEmpty())
    {
        QMessageBox * msgBox = new QMessageBox(QMessageBox::Warning, "提示", "请先添加图片");
        msgBox->show();
        return;
    }
    QFileInfo fileInfo(gfilePath);
    QString directoryPath = fileInfo.path();
    if(!directoryPath.isEmpty())
    {
        QDesktopServices::openUrl(QUrl::fromLocalFile(directoryPath));
    }else
    {
        QMessageBox * msgBox = new QMessageBox(QMessageBox::Warning, "提示", "请先添加图片");
        msgBox->show();
    }
}

/************************************************************************
 *二维码生成和解析器
************************************************************************/
QImage g_qrCodeImage;
void MainWindow::on_pushButton_makeQR_clicked()
{
    if(ui->textEdit_QRText->toPlainText().isEmpty())
    {
        QMessageBox * msgBox = new QMessageBox(QMessageBox::Warning, "提示", "请先添加二维码所包含的信息");
        msgBox->show();
        return;
    }
    QString inputText = ui->textEdit_QRText->toPlainText();
    QImage qrCodeImage = qrCodeEncoder.encodeData(inputText);
    g_qrCodeImage = qrCodeImage;
    QPixmap pixmap = QPixmap::fromImage(qrCodeImage);
    pixmap = pixmap.scaled(ui->label_qrCode->size() * 0.8, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    //ui->label_qrCode->setScaledContents(true);//自适应label窗口大小
    ui->label_qrCode->setPixmap(pixmap);
}

void MainWindow::on_pushButton_saveQR_clicked()
{
    QMessageBox * msgBox;
    if(g_qrCodeImage.isNull())
    {
        msgBox = new QMessageBox(QMessageBox::Warning, "提示", "当前无二维码图片需要保存");
        msgBox->show();
        return;
    }
    // 打开文件对话框选择保存的路径
    QStringList filters;
    filters << "Image files (*.png)"<<"Image files (*.jpg)";
    QString fileName = QFileDialog::getSaveFileName(nullptr, "选择保存路径", "", filters.join(";;"));
    // 创建一个新的 QImage 对象，尺寸与原图相同，并填充为白色
    QImage newImage(g_qrCodeImage.size() * 1.2, QImage::Format_ARGB32);
    newImage.fill(Qt::white);
    // 使用 QPainter 将原图绘制到新的图像上
    QPainter painter(&newImage);
    int x = (newImage.width() - g_qrCodeImage.width()) / 2;
    int y = (newImage.height() - g_qrCodeImage.height()) / 2;
    painter.drawImage(x, y, g_qrCodeImage);
    if (!newImage.save(fileName)) {
        msgBox = new QMessageBox(QMessageBox::Warning, "提示", "保存失败");
        msgBox->show();
        return;
    }
    msgBox = new QMessageBox(QMessageBox::Information, "提示", "保存成功");
    msgBox->show();
}

void MainWindow::on_pushButton_addQR_clicked()
{
    QMessageBox * msgBox;
    // 打开文件对话框选择PNG和JPG图片
    QStringList filters;
    filters << "Image files (*.png *.jpg)";
    QString filePath = QFileDialog::getOpenFileName(nullptr, "选择图片", "", filters.join(";;"));
    if (!filePath.isEmpty())
    {
        QImage image;
        image.load(filePath);
        g_qrCodeImage = image;
        QPixmap pixmap = QPixmap::fromImage(image);
        pixmap = pixmap.scaled(ui->label_qrCode->size() * 0.8, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        //ui->label_qrCode->setScaledContents(true);
        ui->label_qrCode->setPixmap(pixmap);
        msgBox = new QMessageBox(QMessageBox::Warning, "提示", "添加二维码成功");
        msgBox->show();
    }else
    {
        msgBox = new QMessageBox(QMessageBox::Warning, "提示", "添加二维码失败");
        msgBox->show();
        return;
    }
}

bool isValidUrl(const QString &url)
{
    // 定义一个正则表达式来匹配网址
    QRegularExpression re("^(https?:\\/\\/)?" // 协议 (http 或 https)
                          "((([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,})|" // 域名
                          "localhost|" // 本地主机
                          "(\\d{1,3}\\.){3}\\d{1,3})" // IP 地址
                          "(\\:\\d+)?(\\/[^\\s]*)?$"); // 端口和路径
    QRegularExpressionMatch match = re.match(url);
    return match.hasMatch();
}

void MainWindow::on_pushButton_analysisQR_clicked()
{
    if(g_qrCodeImage.isNull())
    {
        on_pushButton_addQR_clicked();
    }
    QZXing decoder;//对二维码进行解码
    decoder.setDecoder( QZXing::DecoderFormat_QR_CODE | QZXing::DecoderFormat_EAN_13 );
    decoder.setSourceFilterType(QZXing::SourceFilter_ImageNormal);
    decoder.setTryHarderBehaviour(QZXing::TryHarderBehaviour_ThoroughScanning | QZXing::TryHarderBehaviour_Rotate);
    QString result = decoder.decodeImage(g_qrCodeImage);
    if(result.isEmpty()){
        msgBox = new QMessageBox(QMessageBox::Warning, "提示", "解析二维码失败");
        msgBox->show();
        return;
    }
    ui->textEdit_QRText->setText(result);//将二维码信息显示出来
    if(isValidUrl(result))
    {
        QDesktopServices::openUrl(QUrl(result));//如果是网址会用默认浏览器打开网页
    }
}

void MainWindow::processFrame(int requestId, const QImage &img)
{
//    qDebug() << "requestId:" << requestId;
//    qDebug() << "Captured frame:" << img.size();
    // 在这里处理捕获的图像，例如显示或保存
    QPixmap pixmap = QPixmap::fromImage(img);
    pixmap = pixmap.scaled(ui->label_qrCode->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    //ui->label_qrCode->setScaledContents(true);
    ui->label_qrCode->setPixmap(pixmap);
    QZXing decoder;//对二维码进行解码
    decoder.setDecoder( QZXing::DecoderFormat_QR_CODE | QZXing::DecoderFormat_EAN_13 );
    decoder.setSourceFilterType(QZXing::SourceFilter_ImageNormal);
    decoder.setTryHarderBehaviour(QZXing::TryHarderBehaviour_ThoroughScanning | QZXing::TryHarderBehaviour_Rotate);
    QString result = decoder.decodeImage(img);
    if(result.isEmpty())
    {
        ui->textEdit_QRText->setText("获取二维码中...");//将二维码信息显示出来
    }else
    {
        camera->stop();
        capturetimer->stop();
        ui->textEdit_QRText->setText(result);//将二维码信息显示出来
        if(isValidUrl(result))
        {
            QDesktopServices::openUrl(QUrl(result));//如果是网址会用默认浏览器打开网页
        }
        QString filePath = QCoreApplication::applicationDirPath() + "/buff.jpg";
       // 创建 QFile 对象
        QFile file(filePath);
       // 检查文件是否存在
        if (file.exists())
        {
           file.remove();
        }
    }
}

void MainWindow::on_pushButton_scanQR_clicked()
{
    camera->start();
    capturetimer->start(20); // 每20ms捕获一次图像
}

void MainWindow::on_pushButton_exitQR_clicked()
{
    camera->stop();
    capturetimer->stop();
    ui->label_qrCode->clear();
    ui->textEdit_QRText->clear();
    QString filePath = QCoreApplication::applicationDirPath() + "/buff.jpg";
   // 创建 QFile 对象
    QFile file(filePath);
   // 检查文件是否存在
    if (file.exists())
    {
       file.remove();
    }
}
